package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApAuthorMapper;
import com.heima.article.service.ApAuthorService;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class ApAuthorServiceImpl extends ServiceImpl<ApAuthorMapper, ApAuthor> implements ApAuthorService {
    /**
     * 查询作者
     * @param id
     * @return
     */
    //7
    @Override
    public ResponseResult findAuthorById(Integer id) {
        //参数校验
        if (id == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        //查询作者
        ApAuthor apAuthor = this.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getWmUserId,id));
        //封装结果返回
        return ResponseResult.okResult(apAuthor);


    }



    /**
     * 保存作者
     * @param apAuthor
     * @return
     */
    @Override
    public ResponseResult saveAuthor(ApAuthor apAuthor) {
        //校验参数
        if (apAuthor == null || apAuthor.getWmUserId() == null || apAuthor.getUserId() == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        //保存用户
        this.save(apAuthor);
        return ResponseResult.okResult();
    }
}
